#include "I2c.h"
#include "device.h"

static I2Cregisters * const I2Cmodules[] = {
    MODULE_I2C1, MODULE_I2C2, MODULE_NULL
};

VTABLE(I2c, PeripheralModule)
    VMETHOD(Object, dtor) = (void (*)(Object *))&I2c_dtor;
    VMETHOD(PeripheralModule, dtor) = (void (*)(PeripheralModule *))&I2c_dtor;
    VMETHOD(I2c, dtor) = (void (*)(I2c *))&I2c_dtor;
VTABLE_END

void I2c_ctor(I2c *obj, int module, enum I2cMode mode) {
    _PeripheralModule_ctor(&obj->super);
    VHOOK(I2c);
    int length;
    for(length = 0; I2Cmodules[length] != MODULE_NULL; length++);
    if((module < 0) || (module >= length)) { return; }
    obj->super._module = module;
}

void I2c_dtor(I2c *obj) {
    /**/
    _PeripheralModule_dtor(&obj->super);
}

void I2c_setAddress(I2c *obj, int i2cAddress) { }
